var menu = {
	currentPage:"forms/t_swdj_bgswdjb.html",
	swjgUuid:$.cookie('swjgUuid'),
	swjgName:$.cookie('swjgName'),
	czryUuid:$.cookie('czryUuid'),
	czryName:$.cookie('czryName'),
	initMenu:function(){
		$.ajax({
            type: "GET",
            url: config.baseURL + "menu/menuList.action",
            cache:false,
            dataType: "json",
            data : {
                "menu.menuLevel":0,
                "menu.menuType":1
            },
            success: function(data){
                if(data.result.success==true){
                	var childMenu = '<ul class="menu">';
                	$.each(data.menuList, function(index, obj) {
                		childMenu += menu.constructChildMenu(obj.childMenu);
                	});
                	childMenu += '</ul>';
                	$('#menuWrap').html(childMenu);
                }else{
                    alert("获取失败");
                }
            }
        });
    },
    constructChildMenu:function(menuList){
        	var html = '';
        	$.each(menuList, function(index, obj) {
        		html += '<li '+(index==0?'class="cur"':'')+'><a class="menu-li-a" href="javascript:void(0);">'+obj.name+'</a><ul>';
            	$.each(obj.childMenu, function(i, childMenu) {
	        		if(childMenu.formId == 1){
	        			$.cookie('childMenuUuid',childMenu.formId);
	        			$.cookie('childMenuName',childMenu.name);
	        			$.cookie('menuUuid',obj.id);
	        			$.cookie('menuName',obj.name);
	        		}
            		var menuClick = 'onclick="javascript:menu.openFormPage('+childMenu.formId+',\''+obj.name+'\',\''+childMenu.name+'\',\''+obj.id+'\');"';
            		if (index === 0 && i === 0) {
            			html += '<li><a href="javascript:void(0);" class="cur" '+menuClick+' >'+childMenu.name+'</a></li>';
            		} else {
            			html += '<li><a href="javascript:void(0);" '+menuClick+' >'+childMenu.name+'</a></li>';
            		}
            	});
        		html +='</ul></li>';
        	});
    	
    	return html;
    },
    openFormPage:function(id,menuName,childMenuName,menuId){
    	$.ajax({
            type: "GET",
            url: config.baseURL + "form/formInfo.action",
            cache:false,
            dataType: "json",
            data : {
                "form.id":id
            },
            success: function(data){
                if(data.result.success==true){
                	menu.currentPage = "forms/" + data.form.pageName+'?menuUuid='+menuId+'&menuName='+menuName+'&childMenuUuid='+id+'&childMenuName='+childMenuName+'&swjgUuid='+menu.swjgUuid+'&swjgName='+menu.swjgName+'&czryUuid='+menu.czryUuid+'&czryName='+menu.czryName;
                	var mainFrame = parent.frames("mainFrame").document.all;
                	mainFrame.menuName.innerText = menuName;
                	mainFrame.childMenuName.innerText = childMenuName;
                	mainFrame.formPage.src = menu.currentPage;
            	}else{
                    alert("获取失败");
                }
            }
        });
    }
};